<template>
	<div class="oldman_data_part">
		<div class="filter_part">
			<AplidForm ref="query" v-bind="serchConfig" v-model="searchModel"></AplidForm>
		</div>
		<div class="btn_part">
			<button @click="toReset">重置</button>
			<button @click="toSearch">搜索</button>
		</div>
		<div class="table_part">
			<table cellspacing="0" width="100%" style="border-spacing: 0 10px; border-collapse: separate; border-radius: 20px">
				<tr style="background-color: #4da5ffaa; height: 50px">
					<th>所属区域</th>
					<th>设施名称</th>
					<th>运营单位</th>
					<th>负责人</th>
					<th>负责人联系方式</th>
					<th>设施类型</th>
					<th>设施评定等级</th>
					<th>营业状态</th>
					<!-- <th>床位总数</th> -->
					<th>操作</th>
				</tr>
			</table>
			<div class="two_table">
				<el-empty v-if="list.length == 0" description="暂无数据" />
				<table cellspacing="0" width="100%" style="border-spacing: 0 10px">
					<tr v-for="item in list" :key="item.id" style="background-color: #a5d1ffaa; height: 50px">
						<td>{{ item.tableAreaName || '/' }}</td>
						<td>{{ item.soleValue || '/' }}</td>
						<td>{{ item.unitName || '/' }}</td>
						<td>{{ item.personName || '/' }}</td>
						<td>{{ plusXing(item.personTelephone) || '/' }}</td>
						<td>{{ item.typeLabel || '/' }}</td>
						<td>{{ item.standardLabel || '/' }}</td>
						<td>{{ item.stateLabel || '/' }}</td>
						<!-- <td>{{ item.bedTotalNum }}</td> -->
						<td>
							<button style="background-color: #0057a1; color: white; border: none; padding: 3px" @click="openDialog(item)">查看档案</button>
						</td>
					</tr>
				</table>
			</div>
		</div>
		<div class="the_footer_part">
			<AplidPaginate class="pageinate mt10" v-bind="pageReac" layout="prev, pager,next" @change="onPageChange" />
		</div>

		<!-- 打开弹窗 -->
		<aplid-dialog
			whickComm="Archives"
			v-model="dialogVisible"
			width="80%"
			:customeHeader="customeHeader"
			title="档案信息"
			append-to-body
			:close-on-click-modal="false"
			pageName="养老机构"
			:model="rowData"
		>
			<DetailPart
				v-if="dialogVisible"
				@refresh="handleRefresh"
				@refreshPage="handleRefreshPage"
				@rechange="handleOperate"
				:nowRowData="rowData"
				:isBlockchain="true"
			></DetailPart>
		</aplid-dialog>
	</div>
</template>
<script setup lang="ts">
import { ref } from 'vue'
import { getAreaObj } from '@/utils/util'
import DetailPart from './archival/index.vue'
import apiMod from '@/apiMod/index'
import { plusXing } from '@/utils/util'
import AplidPaginate from '@/components/AplidCrud/src/AplidPaginate'
import { AplidAreaSelect } from '@/components/AplidCrud'
import dialogCard from '@/components/AplidDialog/components/Card2.vue'
import { useCommonStore } from '@/stores/common'
let { setGloablParams } = useCommonStore()

let query = ref()
let props = defineProps({
	nowRowData: {
		type: Object,
		default: () => ({}),
	},
})
let list: any = ref([])
let searchModel: any = ref({})
let serchConfig = {
	showBtn: false,
	inline: true,
	labelPosition: 'right',
	labelWidth: 140,
	column: [
	{
				label: '统一信用代码',
				prop: 'creditCode',
				type: 'input',
				span: 6,
			},
			{
				label: '所属区域',
				prop: 'crAreas',
				type: 'AplidAreaSelect',
				span: 6,
			},
			{
				label: '设施名称',
				prop: 'soleValue',
				span: 6,
			},
			{
				label: '联系人',
				prop: 'personName',
				type: 'input',
				span: 6,
			},
			{
				label: '联系方式',
				prop: 'personTelephone',
				type: 'input',
				span: 6,
			},
			{
				label: '运营单位',
				prop: 'unitName',
				type: 'input',
				span: 6,
			},
			{
				label: '设施类型',
				prop: 'type',
				type: 'remoteSelect',
				span: 6,
				code: 'FACILITY_TYPE',
				api: 'getDictItemList',
				filterKey: 'value',
				multiple: false,
			},
			// {
			// 	label: '设施等级',
			// 	prop: 'standard',
			// 	type: 'remoteSelect',
			// 	api: 'getDictItemList',
			// 	code: 'ORG_LEVEL',
			// 	filterKey: 'value',
			// 	multiple: false,
			// 	span: 6,
			// },
			{
				label: '营业状态',
				prop: 'state',
				propName: 'stateLabel',
				type: 'remoteSelect',
				code: 'BUSINESS_STATUS',
				api: 'getDictItemList',
				filterKey: 'value',
				multiple: false,
				changeField: true,
				span: 6,
			}
	],
}
let rowData: any = ref({})
const onPageChange = (data) => {
	pageReac.value = data
	getDataList()
}
const customeHeader = {
		type: 'CardOne',
		title: 'name',
		avatar: 'doorHead',
		tipList: [{ prop: 'stateLabel', type: 'tip-success', label: '营业状态' }],
		tagList: [{ prop: 'creditCode', type: 'success', label: '统一社会信用代码' }],
		menuBtn: [
			{
				icon: 'delete',
				label: '删除养老服务设施',
				type: 'danger',
				operate: 'delete',
				auth: 'view_dpServiceObject_del',
				hide: 'dataStatus==0',
				text: false,
				show: true,
				plain: true,
			},
		],
	}

let dialogVisible = ref(false)
const openDialog = (item) => {
	let params = {
		key: item.soleValue,
		code: 2002,
	}
	apiMod.view_blockchainBackupGeneral_queryBlockchainInfo(params).then((res) => {
		res.data.onBlockchainFlag = 1
		// 处理一下区域
		let obj: any = getAreaObj(res.data, '','set')
		res.data.areas_name = obj.names
		rowData.value = res.data
		dialogVisible.value = true
	})
}
let idCard = ref(undefined)
let pageReac = ref({
	current: 1,
	size: 10,
	total: 0,
})
const getDataList = () => {
	// 处理一下搜索数据
	let ceArea: any = []
	if (searchModel.value.crAreas) {
		ceArea = getAreaObj(searchModel.value.crAreas, '')
		searchModel.value.crAreas = undefined
	}
	let params = {
		idCard: idCard.value,
		...searchModel.value,
		...ceArea,
		pageParaPO: pageReac.value,
	}
	apiMod.view_bcServiceFacility_page(params).then((res) => {
		if (res.code == 0) {
			pageReac.value.total = res.data.total
			res.data.records.forEach(el=>{
				el.tableAreaName = el.areaName
			})
			list.value = res.data.records
		}
	})
}
const handleRefresh = (query, visible = false) => {
	dialogVisible.value = visible
	//   nextTick(() => {
	//     crud.value.refreshChange(query)
	//   })
}
const handleRefreshPage = () => {
	//   nextTick(() => {
	//     crud.value.refreshChange({}, true)
	//   })
}
const handleOperate = (type, row, title) => {
	//   nextTick(() => {
	//     crud.value.handleOperate(type, row, title)
	//   })
}
getDataList()
// 去重置
const toReset = () => {
	query.value.onReset()
	setGloablParams({})
	searchModel.value = {}
	getDataList()
}
// 去搜索
const toSearch = () => {
	console.log('fffff')
	getDataList()
}
</script>
<style lang="scss" scoped>
@import '../style.scss';
</style>
